#ifndef __SV_DAHUA_DEV_HPP__
#define __SV_DAHUA_DEV_HPP__

#include "commprd_adapter.hpp"
#include "main.hpp"

#pragma pack(1)
typedef struct dhdev_general_config{
	int nType;
	char buf[1];
}DHDEV_GENERAL_CONFIG;
#pragma pack()

#define WARN_SIZE_MAX 16 * sizeof( ALARM_CONTROL )

using namespace std;

class dahua_adapter :public commprd_adapter{

public:
	// device config data
	DAHUA_CONFIG device_cfg;
public:

	dahua_adapter();
	~dahua_adapter();

	BOOL initialize();
	void uninit();

	BOOL connect();
	void disconnect();
	
	BOOL configure( STUBPARAM params );

	/* get num of warn in/out */
	u_int32 get_warnin_num();
	u_int32 get_warnout_num();
	
//	BOOL query_warnin_state( void * producer_state , u_int32 size );
//	void set_warnin_state( void * producer_state );
	BOOL query_warnout_state( void * producer_state , u_int32 size );
	void set_warnout_state( void * producer_state );


	/* get/set configuration information from/to remote producer*/
	BOOL get_config( int handle , void * config_p );
	BOOL get_all_config();
	BOOL generate_producer_remote_config(REMOTE_GET_CONFIG_MSG *remote_get_req, int max_bytes);
	BOOL do_get_config( char * bufData , int max_bytes );
	BOOL set_config( int handle , void * config_p );
	BOOL do_set_config( XSocket *pSocket, REMOTE_SET_CONFIG_MSG *pmsg, int max_bytes );
	BOOL update_config();

	/* start/stop the thread which handles the date reveived from producer */
	BOOL start( proxysrv_adapter * proxy_p );
	void stop( proxysrv_adapter * proxy_p );

	/* start/stop listening the alarm reported by producer */
	BOOL start_check_alarm();
	void stop_check_alarm();

	/* send notify to xtreamserver through XSocket */
	BOOL send_prod_notify( XSocket *sock , int MSG_TYPE );
	BOOL send_prod_notify_all( XSocket *sock );

	/* set current time of producer */
	void do_prod_time(TimeSyncMsg *pTimeSync );

	void do_prod_cradle(int nChannel, CRADLEOPRequest *pRequest);

	BOOL do_prod_prepos(MSG_SET_PREPOS_INFO *pPreSetNotify);

	BOOL do_prod_camera( unsigned long arg0, unsigned long arg1 );

	void do_fixed_warnout( int nChannel, int status);

	void do_prod_insert_iframe( unsigned long arg0, unsigned long arg1 );

	BOOL do_prod_snapshot( unsigned long arg0, unsigned long arg1 );

	BOOL do_start_interact( START_INTERACT_REQ *pStartInteractReq );
	void do_stop_interact( uint32_t nVerifyID );
	void do_sendaudio_interact( INTERACT_AUDIO_PKT_MSG *pInteractAudioPkt );

	void do_transparent_command( COMMON_TRANS_MSG *pmsg );
	BOOL do_find_file( XSocket *pSocket, FIND_FILE_REQ *pmsg, int max_bytes );

	/* get image size */
	BOOL get_imagesize( int video_imagesize , int  video_standard , u_int32* pWidth , u_int32 * pHeight );

private:
	/* */
	BOOL read_prepos_from_file( int channel );
	BOOL write_prepos_to_file( int channel );

	int get_pic_format( u_int32 width , u_int32 height);
	BOOL init_interact();
	BOOL get_config_by_channel( u_int32 channel , int cfg_type );
};

#endif
